<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" >
<head th:include="admin/common/resource ::commonHead('首页')" ></head>
<body  style="margin: 0px;padding: 0px" >
<div class="container-fluid">
    <div class="toolbar btn-group-sm" type="toolbar" >
        <h6 style="margin-top: 10px;margin-bottom: 20px" > 后台管理系统 / 分类管理 / 类型 </h6>
        <div style="margin-bottom: 10px;" >
            <button shiro:hasPermission="type:add" onclick="loadPage('/admin/type/add')" type="button" class="btn btn-sm btn-success"> 添加类型 </button>
        </div>
    </div>
    <table class="table">
        <thead>
        <tr>
            <th scope="col"> ID </th>
            <th scope="col"> 类型名 </th>
            <th scope="col"> 类型 </th>
            <th scope="col"> 操作 </th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="type:${list}" >
            <th scope="row" th:text="${type.id}" ></th>
            <td th:text="${type.name}"></td>
            <td th:text="${type.tabType} == 1?'影视':'课程'"></td>
            <td>
                <a shiro:hasPermission="type:edit" class="btn-outline-primary" th:href="@{'/admin/type/edit?id='+${type.id}}">编辑</a>
                <a shiro:hasPermission="type:delete" class="btn-outline-danger" th:href="@{'javascript:destroy('+${type.id}+')'}">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
    <!-- 分页 -->
</div>
</body>
<div th:include="admin/common/resource ::footerJs"></div>
<script th:src="@{/layui/layui.all.js}"></script>
<script >


    function destroy(id){
        layer.confirm('真的删除这个类型吗?', function(index){
            layer.close(index);
            //向服务端发送删除指令
            $.ajax({
                type:'delete',
                url: "/admin/type/delete",
                data: {
                    id: id
                },
                success: function (data) {
                    if(data.code == 1){
                        layer.msg("成功",function () {
                            window.location.reload();
                        },2000)
                    }else{
                        layer.msg("失败")
                    }
                }
            })
        });
    }

</script>